import {fetchChargeList} from '@/services/pay/PayCommon'

export default {
  namespace: 'PIndexChargeTable',

  state: {
    dataTable: {
      total: 0,
      list: [],
    },
  },

  effects: {
    * fetchList({payload}, {call, put}) {
      const response = yield call(fetchChargeList, payload);
      if (response.code === 0) {
        let dataTable = response.data;
        dataTable.list = dataTable.list.map(d => {
          d.payChannelName = d.payChannel ? d.payChannel.name : null;
          return d;
        });
        yield put({
          type: 'chgDataTable',
          payload: response.data,
        });
      }
    },

  },

  reducers: {
    chgDataTable(state, action) {
      return {
        ...state,
        dataTable: action.payload,
      };
    },
  },
};